home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / TREEDIR.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  1KB  |  54 lines

  1. /*
  2. **  TREEDIR.C - simple recursive directory lister
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #ifdef __ZTC__
  11.  #include <dos.h>
  12.  #ifndef _A_SUBDIR
  13.   #define _A_SUBDIR FA_DIREC
  14.  #endif
  15. #elif defined(__TURBOC__)
  16.  #include <dir.h>
  17.  #include <dos.h>
  18.  #define _dos_findfirst(f,a,b) findfirst(f,b,a)
  19.  #define _dos_findnext(b) findnext(b)
  20.  #define find_t ffblk
  21.  #define _A_SUBDIR FA_DIREC
  22.  #define attrib ff_attrib
  23.  #define name ff_name
  24. #else                   /* assume MSC/QC                                */
  25.  #include <dos.h>
  26.  #include <errno.h>
  27. #endif
  28.  
  29. #ifndef SUCCESS
  30.  #define SUCCESS 0
  31. #endif
  32.  
  33. void do_dir(char *path)
  34. {
  35.         char search[67], new[67];
  36.         struct find_t ff;
  37.  
  38.         strcat(strcpy(search, path), "\\*.*");
  39.         if (SUCCESS == _dos_findfirst(search, 0xff, &ff)) do
  40.         {
  41.                 printf("%s\\%s\n", path, ff.name);
  42.                 if (ff.attrib & _A_SUBDIR && '.' != *ff.name)
  43.                 {
  44.                         strcat(strcat(strcpy(new, path), "\\"), ff.name);
  45.                         do_dir(new);
  46.                 }
  47.         } while (SUCCESS == _dos_findnext(&ff));
  48. }
  49.  
  50. void main(void)         /* simple resursive current directory lister    */
  51. {
  52.         do_dir(".");
  53. }
  54.